﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPlusres.Business;

namespace SPlusres.Business.Courseware
{
    public static class CoursewareCategoryExtension
    {
        /// <summary>
        /// To Small Model
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public static List<CoursewareCategoryData.SmallCoursewareCategory> ToSmall(this IQueryable<Data.CoursewareCategory> query)
        {
            return query.Select(m => new CoursewareCategoryData.SmallCoursewareCategory()
            {
                ID = m.ID,
                Name = m.Name
            }).ToList();
        }
    }

    public class CoursewareCategoryData
    {
        public class SmallCoursewareCategory
        {
            /// <summary>
            /// ID
            /// </summary>
            public int ID { get; set; }

            /// <summary>
            /// Name
            /// </summary>
            public string Name { get; set; }
        }

        /// <summary>
        /// Subject List
        /// </summary>
        /// <returns>List</returns>
        public static List<CoursewareCategoryData.SmallCoursewareCategory> List()
        {
            using (var data = new Data.SPlusresDataContext(SystemSetting.ConnectionString))
            {
                return data.CoursewareCategory.ToSmall();
            }
        }
    }
}
